import { Module } from "vuex";
import storage from "@/libs/storage";

const modules: Module<any, any> = {
  namespaced: true,
  state: {
    userInfo: storage.get("userInfo"),
    token: storage.get("token"),
    shopInfo: storage.get("shopInfo"),
    iphone: ""
  },
  mutations: {
    SET_USER_INFO(state, payload) {
      state.userInfo = payload;
    },
    SET_TOKEN(state, payload) {
      state.token = payload;
    },
    SET_IPHONE(state, payload) {
      state.iphone = payload;
    },
    SET_SHOP_INFO(state, payload) {
      state.shopInfo = payload;
    }
  },
  actions: {
    /**
     * @description 设置用户数据
     * @author hlp
     * @param {*} { commit }
     * @param {*} data
     */
    setUserInfo({ commit }, data) {
      commit("SET_USER_INFO", data);
    },
    /**
     * @description 设置店铺数据
     * @author hlp
     * @param {*} { commit }
     * @param {*} data
     */
    setShopInfo({ commit }, data) {
      commit("SET_SHOP_INFO", data);
    },
    /**
     * @description 设置token
     * @author ygd
     * @param {*} { commit }
     * @param {*} data
     */
    setToken({ commit }, data) {
      commit("SET_TOKEN", data);
    }
  },
};

export default modules;
